<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <form id="info">
        <div>
            <label for="usernaem">用户名：</label>
            <input type="text" name="username" id="usernaem">
        </div>
        <div>
            <label for="usernaem">密码：</label>
            <input type="password" name="password" id="password">
        </div>
        <div>
            <input type="button" id="btn" value="提交">
        </div>
    </form>
    <script>
        var btn = document.getElementById('btn')
        btn.onclick = function() {
            var uname = document.getElementById('usernaem').value
            var pwd = document.getElementById('password').value
            var xhr = new XMLHttpRequest()
            xhr.open('post', 'http://www.liulongbin.top:3006/api/formdata')
            var form = document.getElementById('info')
            var fd = new FormData(form);
            // fd.append('uname', uname)
            // fd.append('pwd222', pwd)
            // console.log(str)
            // xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded')
            xhr.send(fd)
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    var ret = xhr.responseText
                    console.log(ret)
                }
            }
        }
    </script>
</body>

</html>